<?php
namespace Admin\Controller;
use Think\Controller;

class WallpaperController extends HomeController {

	/*
	* Function:		WallpaperList
	* Description:	商品分类列表
	*/
    public function wallpaperList(){
		$filter = I('param.');
		$page =  I('get.p',1);
		$pageSize = 10;
		$filter = returnFilter($filter);
		$list = D('Wallpaper')->getWallpaperList($page,$filter,$pageSize);
		$count =  D('Wallpaper')->getWallpaperCount($filter);
		$pages = getpage($count,$pageSize,$filter);
		$show = $pages->show();
		$this->assign('list',$list);
		$this->assign('page',$show);
		$this->assign('filter',$filter);
		$this->display();
    }
	
	/*
	* Function:		addWallpaper
	* Description:	添加商品分类
	*/
	public function addWallpaper(){
		$ret = array();
		if(IS_POST){
			$data = I('post.');
			$data['addtime'] = date('Y-m-d H:i:s',time());
			if(D('Wallpaper')->addWallpaper($data)){
				$ret = array('code'=>1,'message'=>'添加成功');
				$this->ajaxReturn($ret);
			}else{
				$ret = array('code'=>0,'message'=>'添加失败!');
				$this->ajaxReturn($ret);
			}
		}else{
			$this->display();
		}
	}
	
	/*
	* Function:		editWallpaper
	* Description:	编辑快递
	* @param:		$id int id
	*/
	public function editWallpaper($id = ''){
		if(IS_POST){
			$data = I('post.');
			$ret = D('Wallpaper')->updateWallpaper($data);
			if($ret!==false){
				$ret = array('code'=>1,'message'=>'更新成功');
				$this->ajaxReturn($ret);
			}else{
				$ret = array('code'=>0,'message'=>'更新失败!');
				$this->ajaxReturn($ret);
			}
		}else{
			if(empty($id)){
				$this->error('参数异常');
			}else{
				$info = D('Wallpaper')->getWallpaperInfo($id);
				$this->assign('info',$info);
				$this->display();
			}
		}
	}
	
	/*
	* Function:		deleteWallpaper
	* Description:	删除表情包
	* @param:		$id
	*/
	public function deleteWallpaper($id = ''){
		if(M('wallpaper_list')->where(['id'=>$id])->delete()){
			$ret = array('code'=>1,'message'=>'操作成功');
			$this->ajaxReturn($ret);
		}else{
			$ret = array('code'=>0,'message'=>'操作失败!');
			$this->ajaxReturn($ret);
		}
	}
}